package prvi.wen.terp.mapper;

import org.apache.ibatis.annotations.Insert;
import prvi.wen.terp.model.UserEntity;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;




import java.util.Date;
import java.util.List;



public interface UserMapper{
	
    //interface 接口 不需要实现类
    @Select("SELECT * FROM test_user")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "uName", column = "u_name"),
            @Result(property = "uPassword", column = "u_password"),
            @Result(property = "role", column = "role"),
            @Result(property = "lastLogin", column = "last_login" ,javaType = Date.class),
            @Result(property = "createdBy", column = "created_by"),
            @Result(property = "createdDate", column = "created_date" ,javaType = Date.class),
            @Result(property = "updatedBy", column = "updated_by"),
            @Result(property = "updatedDate", column = "updated_date",javaType = Date.class),
            @Result(property = "status", column = "status"),
    })
    List<UserEntity> getAll();

    @Select("SELECT * FROM test_user WHERE id = #{id}")
    @Results({
        @Result(property = "id", column = "id"),
        @Result(property = "uName", column = "u_name"),
        @Result(property = "uPassword", column = "u_password"),
        @Result(property = "role", column = "role"),
        @Result(property = "lastLogin", column = "last_login" ,javaType = Date.class),
        @Result(property = "createdBy", column = "created_by"),
        @Result(property = "createdDate", column = "created_date" ,javaType = Date.class),
        @Result(property = "updatedBy", column = "updated_by"),
        @Result(property = "updatedDate", column = "updated_date",javaType = Date.class),
        @Result(property = "status", column = "status"),
            })
    UserEntity getOne(Long id);
    
    @Select("SELECT * FROM test_user WHERE u_name = #{name}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "uName", column = "u_name"),
            @Result(property = "uPassword", column = "u_password"),
            @Result(property = "role", column = "role"),
            @Result(property = "lastLogin", column = "last_login" ,javaType = Date.class),
            @Result(property = "createdBy", column = "created_by"),
            @Result(property = "createdDate", column = "created_date" ,javaType = Date.class),
            @Result(property = "updatedBy", column = "updated_by"),
            @Result(property = "updatedDate", column = "updated_date",javaType = Date.class),
            @Result(property = "status", column = "status"),
    })
    List<UserEntity> getByName(String name);
    
//    @Select("SELECT * FROM test_user WHERE u_name = #{name} and u_password = #{password}")
//    @Results({
//            @Result(property = "id", column = "id"),
//            @Result(property = "uName", column = "u_name"),
//            @Result(property = "uPassword", column = "u_password"),
//            @Result(property = "role", column = "role"),
//            @Result(property = "lastLogin", column = "last_login" ,javaType = Date.class),
//            @Result(property = "createdBy", column = "created_by"),
//            @Result(property = "createdDate", column = "created_date" ,javaType = Date.class),
//            @Result(property = "updatedBy", column = "updated_by"),
//            @Result(property = "updatedDate", column = "updated_date",javaType = Date.class),
//            @Result(property = "status", column = "status"),
//    })
//    List<UserEntity> getByNameAndPassword(String name,String password);

    @Insert("insert into test_user(u_name,u_password,role,last_login,created_by,created_date,status) " +
            "values(#{uName},#{uPassword},#{role},#{lastLogin},#{createdBy},#{createdDate},#{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void addUser(UserEntity userEntity);

}
